package com.lovestudying.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.lovestudying.entity.Tab;
import com.lovestudying.service.TabService;
import com.lovestudying.service.impl.TabServiceImpl;

/**
 * Servlet implementation class TabServlet
 */
@WebServlet("/TabServlet")
public class TabServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private TabService tabService = new TabServiceImpl();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TabServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String op = request.getParameter("op");
		if ("getAllTab".equals(op)) {
			doGetAllTab(request,response);
		}
	}

	private void doGetAllTab(HttpServletRequest request, HttpServletResponse response) throws IOException {
		//调用业务层
		List<Tab> tab = tabService.getTab();
		Gson gson = new Gson();
		String json = gson.toJson(tab);
		response.setContentType("application/json");
		response.getWriter().write(json);
	}

}
